#ifndef _SMS_TASK_H
#define _SMS_TASK_H

#include "fifoMsgQueue.h"

#ifdef __cplusplus
extern "C"{
#endif

#define AT_SMS_CALLED                   100
#define AT_SMS_MAXLEN                   140 /* For ASCII 160, UNICODE16 70x2=140 */

#define AT_CMD_MAXLEN                   262       /* 260+2 */
#define AT_RSP_MINLEN                   6
#define AT_RSP_MAXLEN                   668       /* mt response msg limited to 668 */

#define MGR2SMS_MSGQUEUE_SIZE           200       
#define MSG_SMS_RETRY_COUNT             (3)

#define CR              "\r"            // 结束标志
#define CRLF            "\r\n"          // 回车换行
#define CRLF_OK_CRLF    "\r\nOK\r\n"    // 操作成功
#define CRLF_OK         "\r\nOK"    // 操作成功
#define CRLF_ERROR      "\r\nERROR"     // 操作失败
#define CRLF_ERROR_CRLF "\r\nERROR\r\n" // 操作失败
#define CRLF_CMS_ERR_CRLF "+CMS ERROR:"
#define CTRL_Z          "\032"          // 发送短信时短信内容结束标志 CTRL+Z

#define AT_BUFFER_SIZE          512     // AT命令缓冲区大小
#define COMMAND_GENERAL_LEN     128     // 命令通常长度(字节)
#define TEL_LEN_MAX             20      // 电话号码最大长度

#define AT_COMMAND_INTERVAL     100000  // AT命令发送时间间隔(微秒)
#define CONFIG_COMMAND_TIMEOUT  5        // 设置类AT命令超时时间(秒)
#define GENERAL_DIAL_TIMEOUT    40      // 拨号超时时间(秒)
#define GENERAL_HANG_TIMEOUT    5       // 挂断超时时间(秒)
#define GENERAL_OFFLINE_TIMEOUT 2       // 从在线状态切换到命令状态的超时时间(秒)
#define GENERAL_RESET_TIMEOUT   5       // 重启超时时间(秒)

#define MODEM_MSG_MAX_COUNT     20      // Modem储存最大短信条数
#define MODEM_MSG_MAX_SIZE      160     // Modem短信最大容量
#define MODEM_TEL_MAX_SIZE      20      // 电话号码最大长度
#define WAN_CHECK_INTERVAL      30
#define MAX_FAILED_PING         6

typedef enum msgID {
    MSG_ID_SMS = 1,
    MSG_ID_GET_SIM_STATE,
    MSG_ID_SIM_STATE_RSP,
    MSG_ID_STATUS,
    MSG_ID_ALARM,
    MSG_ID_RESET,
} MSG_ID;

typedef enum sendStatus {
    MSG_SMS_SENDING = 1,
    MSG_SMS_FAIL,
    MSG_SMS_WAIT_CONFIRM,
    MSG_SMS_ACCEPTED,
    MSG_SMS_LOST,

    MSG_SMS_IDEL
} MSG_SMS_STATUS;

typedef struct tagMsgHeader
{
    int32_t   msgId;
} MSG_HEADER;

typedef struct tagSmsMsg {
    MSG_HEADER  header;
    char        callerId[16];
    int32_t     smsLength;
    int32_t     format;
    char        text[AT_SMS_MAXLEN];
} SMS_MSG;

typedef struct tagSimState {
    MSG_HEADER header;
    int32_t valid;
} SIM_STATE;

typedef struct tagSmsAlarm {
    MSG_HEADER header;
    int32_t id;
    int32_t reason;
    int32_t action;
} SMS_ALARM;

extern FIFO_MSGQUEUE mgr2SmsMsgQueue;             /* mgr ---normal msgs--> sms */
extern FIFO_MSGQUEUE sms2MgrMsgQueue;             /* sms ---normal msgs--> mgr */
extern bool smsIsOk;
bool CheckTick();
bool initckeckWan();
bool initSmsTask();
void stopSmsTask();
void initMutex();
void SetcheckWanTrue();
bool GetCheckWanThreadIsOk();
#ifdef MODULE_TEST
void setTestCheckWan();
void setTestSms();
#endif

#ifdef __cplusplus
}
#endif


#endif //_SMS_TASK_H
